<?php
/**
 * Created by PhpStorm.
 * User: minicart
 * Date: 2018/12/2
 * Time: 12:16
 */
namespace app\models;

use think\Model;

/**
 * Class GradesModel
 * @package app\models
 */
class GradesModel extends Model
{
    protected $table = 'edu_class_manage';

    /**
     * @param $param
     * @return array
     * @throws \think\exception\DbException
     */
    public function getClassManageLists($param)
    {
        $page = isset($param['page']) ? (int) $param['page'] : 1;
        $listRows = isset($param['limit']) ? (int) $param['limit'] : 10;
        $where = [];
        if (isset($param['class_name']) && '' !== $param['class_name']) {
            $where['class_name'] = ['like', $param['class_name'].'%'];
        }
        $listData = self::where($where)
            ->paginate($listRows, false, ['page' => $page])
            ->toArray();
        if (!empty($listData)) {
            foreach ($listData['data'] as &$item) {
                $item['course_name'] = CourseModel::get($item['course_id'])['course_name'];
                $item['headmaster'] = TeacherModel::get($item['headmaster'])['teacher_name'];
                $item['teacher'] = TeacherModel::get($item['teacher'])['teacher_name'];
                $item['assistant'] = TeacherModel::get($item['assistant'])['teacher_name'];
                $item['class_room'] = ClassRoomModel::get($item['class_room'])['class_name'];
                $item['preoccupation'] = $item['preoccupation'] ? $item['preoccupation'] : '不限';

            }
        }
        return $listData;
    }
}